package net.sansi.v3correctserver.validator.impl;

import net.sansi.v3correctserver.validator.PathValid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

public class PathValidValidator implements ConstraintValidator<PathValid, String> {

    private static final Pattern FOLDER_NAME_PATTERN = Pattern.compile("^[\\p{L}\\p{N}_.-]+$");

    @Override
    public void initialize(PathValid constraintAnnotation) {
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null || value.isEmpty()) return true;
        return FOLDER_NAME_PATTERN.matcher(value).matches();
    }
}
